home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / FunctionSetInfo / Sources / TestMathFSet.c < prev   
Encoding:
C/C++ Source or Header  |  1996-11-19  |  2.1 KB  |  85 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TestMathFSet.c
  3.  
  4.     Contains:    MPW tool that will demonstrate how to use GetFunctionInfo.
  5.  
  6.     Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __MATHFSET__
  12. #include "MathFSet.h"
  13. #endif
  14.  
  15. #ifndef __LIBRARYMANAGERUTILITIES__
  16. #include <LibraryManagerUtilities.h>
  17. #endif
  18.  
  19.  
  20. int main()
  21. {
  22.     OSErr    err;
  23.     TFunctionSetID    id;
  24.     MathFunction1ProcPtr func1;
  25.     MathFunction2ProcPtr func2;
  26.     TFunctionSetInfo* info;
  27.     
  28.     err = InitLibraryManager(0, kCurrentZone, kNormalMemory);
  29.     if (err != kNoError)
  30.     {
  31.         printf("### ERROR: InitLibraryManager failed. errror=%d\n", err);
  32.         return 1;
  33.     }
  34.     
  35.     // Get the TFunctionSetInfo object we will use to iterate over all known function
  36.     // sets that specified a interface of kMathFSetInterfaceID.
  37.  
  38.     info = GetFunctionSetInfo(kMathFSetInterfaceID, &err);
  39.     if (info == NULL)
  40.     {
  41.         printf("### ERROR: #%d getting the TFunctionSetInfo object\n", err);
  42.         return 1;
  43.     }
  44.     
  45.     // Iterate over all the functions sets with an interface of kMathFSetInterfaceID,
  46.     // calling the MathFunction1 and MathFunction2 functions for each one.
  47.     
  48.     while (id = FSInfoNext(info))
  49.     {
  50.         // At this point we could make calls like FSInfoGetLibraryFile,
  51.         // FSInfoGetVersion, and FSInfoGetLibrary. FSInfoGetLibraryFile can
  52.         // be useful for opening up the library file that the function set
  53.         // is in and getting a resource that has a "user readable" name
  54.         // for the function set that you can display for a user so he
  55.         // can choose which function set he wants.
  56.         
  57.         printf("\nCalling functions for %s function set.\n", id);
  58.  
  59.         func1 = GetFunctionPointer(id, kMathFunctionName1, &err);
  60.         if (err == kNoError)
  61.         {
  62.             int result = (*func1)(5,2);
  63.             printf("MathFunction1(5,2) = %d.\n",result);
  64.         }
  65.         else
  66.             printf("### ERROR: #%d getting MathFunction1\n", err);
  67.  
  68.         func2 = GetFunctionPointer(id, kMathFunctionName2, &err);
  69.         if (err == kNoError)
  70.         {
  71.             int result = (*func2)(4,3,2);
  72.             printf("MathFunction2(4,3,2) = %d.\n",result);
  73.         }
  74.         else
  75.             printf("### ERROR: #%d getting MathFunction2\n", err);
  76.     }
  77.     
  78.     // Free up the memory that the TFunctionSetInfo used up
  79.     FreeFunctionSetInfo(info);
  80.     
  81.     CleanupLibraryManager();
  82.     
  83.     return 0;
  84. }
  85.